export default {
    props: {
        _input: {
            required: false,
        },
    },
    data() {
            // @VExportData-Start
            return {
                form: {
                    project_id: null,
                    staff_id: null,
                    owner_id: null,
                    customer_id: null,
                    item_id: null,
                    wh_area_id: null,
                    project_name: null,
                    owner_name: null,
                    customer_name: null,
                    item_name: null,
                    wh_area_code: null,
                    operator: null,
                },
                grid1: {
                    isChanged: false,
                    selections: [],
                    checkedRows: [],
                    selection: null,
                },
                grid2: {
                    isChanged: false,
                    selections: [],
                    checkedRows: [],
                    selection: null,
                },
                vjson: {
                    layout: 'SimpleGrid',
                    toolbar: {
                        xtype: 'toolbar',
                        items: [
                            {
                                xtype: 'button',
                                text: '查询',
                                hidden: false,
                                disabled: false,
                                loading: false,
                                cls: '',
                                type: 'primary',
                                plain: true,
                                round: false,
                                circle: false,
                                link: false,
                                size: 'default',
                                iconCls: 'element Search',
                                listeners: {
                                    click: '{button3_click}',
                                },
                            },
                            {
                                xtype: 'button',
                                iconCls: 'fa HandPointRight',
                                text: '任务指派',
                                plain: true,
                                listeners: {
                                    click: '{button1_click}',
                                },
                                bind: {
                                    disabled: '{button1_disabled}',
                                },
                            },
                            {
                                xtype: 'button',
                                text: '任务解绑',
                                iconCls: 'element CloseBold',
                                plain: true,
                                bind: {
                                    disabled: '{button2_disabled}',
                                },
                                listeners: {
                                    click: '{button2_click}',
                                },
                            },
                            {
                                xtype: 'button',
                                iconCls: 'fa Print',
                                text: '打印发货单',
                                plain: true,
                                listeners: {
                                    click: '{button4_click}',
                                },
                                bind: {},
                            },
                            {
                                xtype: 'button',
                                text: '重置',
                                iconCls: 'element RefreshLeft',
                                plain: true,
                                type: 'warning',
                                lookup: {},
                                listeners: {
                                    click: '{button5_click}',
                                },
                            },
                            {
                                xtype: 'staticfield',
                                fieldLabel: 'project_id',
                                bind: {
                                    value: '{form.project_id}',
                                },
                                hidden: true,
                                disabled: false,
                                loading: false,
                                cls: '',
                                placeholder: '请输入',
                                size: 'default',
                                readonly: false,
                                weight: 1,
                                text: '',
                                lookup: {},
                            },
                            {
                                xtype: 'staticfield',
                                fieldLabel: 'staff_id',
                                bind: {
                                    value: '{form.staff_id}',
                                },
                                hidden: true,
                                disabled: false,
                                loading: false,
                                cls: '',
                                placeholder: '请输入',
                                size: 'default',
                                readonly: false,
                                weight: 1,
                                text: '',
                                lookup: {},
                            },
                            {
                                xtype: 'staticfield',
                                fieldLabel: 'owner_id',
                                bind: {
                                    value: '{form.owner_id}',
                                },
                                hidden: true,
                                disabled: false,
                                loading: false,
                                cls: '',
                                placeholder: '请输入',
                                size: 'default',
                                readonly: false,
                                weight: 1,
                                text: '',
                                lookup: {},
                            },
                            {
                                xtype: 'staticfield',
                                fieldLabel: 'customer_id',
                                bind: {
                                    value: '{form.customer_id}',
                                },
                                hidden: true,
                                disabled: false,
                                loading: false,
                                cls: '',
                                placeholder: '请输入',
                                size: 'default',
                                readonly: false,
                                weight: 1,
                                text: '',
                                lookup: {},
                            },
                            {
                                xtype: 'staticfield',
                                fieldLabel: 'item_id',
                                bind: {
                                    value: '{form.item_id}',
                                },
                                hidden: true,
                                disabled: false,
                                loading: false,
                                cls: '',
                                placeholder: '请输入',
                                size: 'default',
                                readonly: false,
                                weight: 1,
                                text: '',
                                lookup: {},
                            },
                            {
                                xtype: 'staticfield',
                                fieldLabel: 'wh_area_id',
                                bind: {
                                    value: '{form.wh_area_id}',
                                },
                                hidden: true,
                                disabled: false,
                                loading: false,
                                cls: '',
                                placeholder: '请输入',
                                size: 'default',
                                readonly: false,
                                weight: 1,
                                text: '',
                                lookup: {},
                            },
                            {
                                xtype: 'slot',
                                name: 'custom1',
                            },
                        ],
                    },
                    form: [
                        {
                            xtype: 'form',
                            colsOfRow: '4',
                            items: [
                                {
                                    xtype: 'combogrid',
                                    fieldLabel: '操作员',
                                    bind: {
                                        value: '',
                                    },
                                    hidden: false,
                                    disabled: false,
                                    loading: false,
                                    cls: '',
                                    placeholder: '请输入',
                                    size: 'default',
                                    readonly: false,
                                    weight: 1,
                                    allowCustomInput: false,
                                    widget: 'StaffSearch',
                                    param: {},
                                    lookup: {},
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '物流订单号',
                                    bind: {
                                        value: '',
                                    },
                                    lookup: {},
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '客户订单编号',
                                    bind: {
                                        value: '',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '出库通知单号',
                                    bind: {
                                        value: '',
                                    },
                                },
                                {
                                    xtype: 'combogrid',
                                    fieldLabel: '项目名称',
                                    bind: {
                                        value: '{form.project_name}',
                                    },
                                    hidden: false,
                                    disabled: false,
                                    loading: false,
                                    cls: '',
                                    placeholder: '请输入',
                                    size: 'default',
                                    readonly: false,
                                    weight: 2,
                                    allowCustomInput: false,
                                    widget: 'ProjectSearch',
                                    param: {},
                                    lookup: {
                                        project_id: '{form.project_id}',
                                        project_name: '{form.project_name}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '波次号',
                                    bind: {
                                        value: '',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '调度单号',
                                    bind: {
                                        value: '',
                                    },
                                    lookup: {},
                                },
                                {
                                    xtype: 'combogrid',
                                    fieldLabel: '货主名称',
                                    bind: {
                                        value: '{form.owner_name}',
                                    },
                                    hidden: false,
                                    disabled: false,
                                    loading: false,
                                    cls: '',
                                    placeholder: '请输入',
                                    size: 'default',
                                    readonly: false,
                                    weight: 2,
                                    allowCustomInput: false,
                                    widget: 'OwnerSearch',
                                    param: {},
                                    lookup: {
                                        owner_id: '{form.owner_id}',
                                        owner_name: '{form.owner_name}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '托盘号',
                                    bind: {
                                        value: '',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '箱号',
                                    bind: {
                                        value: '',
                                    },
                                },
                                {
                                    xtype: 'combogrid',
                                    fieldLabel: '客户名称',
                                    bind: {
                                        value: '{form.customer_name}',
                                    },
                                    hidden: false,
                                    disabled: false,
                                    loading: false,
                                    cls: '',
                                    placeholder: '请输入',
                                    size: 'default',
                                    readonly: false,
                                    weight: 2,
                                    allowCustomInput: false,
                                    widget: 'CustomSearch',
                                    param: {},
                                    lookup: {
                                        customer_id: '{form.customer_id}',
                                        customer_name: '{form.customer_name}',
                                    },
                                },
                                {
                                    xtype: 'combogrid',
                                    fieldLabel: '物料名称',
                                    bind: {
                                        value: '{form.item_name}',
                                    },
                                    hidden: false,
                                    disabled: false,
                                    loading: false,
                                    cls: '',
                                    placeholder: '请输入',
                                    size: 'default',
                                    readonly: false,
                                    weight: 1,
                                    allowCustomInput: false,
                                    widget: 'ItemSearch',
                                    param: {},
                                    lookup: {},
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '收货地区',
                                    bind: {
                                        value: '',
                                    },
                                    hidden: false,
                                    disabled: false,
                                    loading: false,
                                    cls: '',
                                    placeholder: '请输入',
                                    size: 'default',
                                    readonly: false,
                                    weight: 1,
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '收货详细地址',
                                    bind: {
                                        value: '',
                                    },
                                    hidden: false,
                                    disabled: false,
                                    loading: false,
                                    cls: '',
                                    placeholder: '请输入',
                                    size: 'default',
                                    readonly: false,
                                    weight: 2,
                                },
                                {
                                    xtype: 'combogrid',
                                    fieldLabel: '工作区编号',
                                    bind: {
                                        value: '{form.wh_area_code}',
                                    },
                                    hidden: false,
                                    disabled: false,
                                    loading: false,
                                    cls: '',
                                    placeholder: '请输入',
                                    size: 'default',
                                    readonly: false,
                                    weight: 1,
                                    allowCustomInput: false,
                                    widget: 'AreaSearch',
                                    param: {},
                                    lookup: {
                                        wh_area_id: '{form.wh_area_id}',
                                        wh_area_code: '{form.wh_area_code}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '操作员',
                                    bind: {
                                        value: '{form.operator}',
                                    },
                                    hidden: false,
                                    disabled: true,
                                    loading: false,
                                    cls: '',
                                    placeholder: '请输入',
                                    size: 'default',
                                    readonly: false,
                                    weight: 1,
                                    lookup: {},
                                },
                            ],
                            lookup: {},
                            labelWidth: '100',
                            maxHeight: '',
                            heightMode: 'auto',
                            height: '150',
                        },
                    ],
                    items: [
                        {
                            xtype: 'split',
                            items: [
                                {
                                    items: [
                                        {
                                            xtype: 'aggrid',
                                            columns: [
                                                {
                                                    dataIndex: 'so_id',
                                                    header: '出库订单ID',
                                                    xtype: 'aggridcolumn',
                                                    editable: true,
                                                    editor: {},
                                                    hidden: true,
                                                },
                                                {
                                                    dataIndex: 'ship_id',
                                                    header: '发运ID',
                                                    xtype: 'aggridcolumn',
                                                    editable: true,
                                                    editor: {},
                                                    hidden: true,
                                                },
                                                {
                                                    dataIndex: '__actions',
                                                    header: '查看订单详情',
                                                    xtype: 'aggridcolumn',
                                                    editable: false,
                                                    replaceFor: '',
                                                    isActions: true,
                                                    listeners: {
                                                        click: 'system.showDialog(\'/outbound/so/SoDetailDialog.vue\',{title:\'出库通知单\',so:this.refs.grid1.getSelectedRows()[0]})',
                                                    },
                                                    actions: [
                                                        {
                                                            text: '查看详情',
                                                            show: true,
                                                        },
                                                    ],
                                                },
                                                {
                                                    dataIndex: 'urgent_type',
                                                    header: '紧急程度',
                                                    xtype: 'aggridcolumn',
                                                    editable: false,
                                                    dict: 'URGENT_TYPE',
                                                },
                                                {
                                                    dataIndex: 'dates',
                                                    header: '订单创建日期',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'so_code',
                                                    header: '出库通知单号',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'logistics_order_code',
                                                    header: '物流订单号',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'customer_order_code',
                                                    header: '客户订单编号',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'project_name',
                                                    header: '项目名称',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'owner_name',
                                                    header: '货主名称',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'customer_name',
                                                    header: '客户名称',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'order_type',
                                                    header: '订单类型',
                                                    xtype: 'aggridcolumn',
                                                    replaceFor: '',
                                                    dict: 'ORDER_TYPE',
                                                },
                                                {
                                                    dataIndex: 'order_biz_type',
                                                    header: '出库业务类型',
                                                    xtype: 'aggridcolumn',
                                                    dict: 'ORDER_BIZ_TYPE',
                                                },
                                                {
                                                    dataIndex: 'status',
                                                    header: '订单状态',
                                                    xtype: 'aggridcolumn',
                                                    dict: 'OUTBOUND_STATUS',
                                                },
                                                {
                                                    dataIndex: 'estimate_out_time',
                                                    header: '预估发货时间',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'estimate_revice_time',
                                                    header: '预估到货时间',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'is_cover',
                                                    header: '允许扫码覆盖',
                                                    xtype: 'aggridcolumn',
                                                    dict: 'YES_NO',
                                                },
                                                {
                                                    dataIndex: 'remark',
                                                    header: '备注',
                                                    xtype: 'aggridcolumn',
                                                },
                                            ],
                                            hidden: false,
                                            disabled: false,
                                            loading: false,
                                            cls: '',
                                            height: '300px',
                                            pagination: true,
                                            pageSize: 50,
                                            autoLoad: true,
                                            rowNumber: false,
                                            hiLightSelectedRow: false,
                                            isBindMode: false,
                                            rowDragable: false,
                                            pageSizeOption: [
                                                {
                                                    value: '20',
                                                },
                                                {
                                                    value: '50',
                                                },
                                                {
                                                    value: '100',
                                                },
                                                {
                                                    value: '200',
                                                },
                                                {
                                                    value: '300',
                                                },
                                                {
                                                    value: '500',
                                                },
                                                {
                                                    value: '1000',
                                                },
                                            ],
                                            mode: 'checkbox',
                                            dataSource: {
                                                sqlId: 'querySoList',
                                                method: 'invoke',
                                                params: {
                                                    start_date: '{form.start_date}',
                                                    end_date: '{form.end_date}',
                                                    staff_id: '{form.staff_id}',
                                                    so_code: '{form.so_code}',
                                                    project_id: '{form.project_id}',
                                                    logistics_order_code: '{form.logistics_order_code}',
                                                    customer_order_code: '{form.customer_order_code}',
                                                    owner_id: '{form.owner_id}',
                                                    order_type: '{form.order_type}',
                                                    order_biz_type: '{form.order_biz_type}',
                                                    customer_name: '{form.customer_name}',
                                                    urgent_type: '{form.urgent_type}',
                                                    rece_area: '{form.rece_area}',
                                                    is_overstock: '{form.is_overstock}',
                                                    customer_id: '{form.customer_id}',
                                                    is_cover: '{form.is_cover}',
                                                    rece_address: '{form.rece_address}',
                                                },
                                            },
                                            reference: 'grid1',
                                            heightMode: 'fit',
                                            listeners: {
                                                onRowClick: '{grid1_onRowClick}',
                                            },
                                            lookup: {},
                                            title: '订单汇总',
                                        },
                                    ],
                                    xtype: 'splitarea',
                                },
                                {
                                    items: [
                                        {
                                            xtype: 'toolbar',
                                            items: [
                                                {
                                                    xtype: 'staticfield',
                                                    fieldLabel: '拣货任务明细列表',
                                                    bind: {
                                                        value: '',
                                                    },
                                                    hidden: false,
                                                    disabled: false,
                                                    loading: false,
                                                    cls: '',
                                                    placeholder: '请输入',
                                                    size: 'default',
                                                    readonly: false,
                                                    weight: 1,
                                                    text: '',
                                                    isBlod: true,
                                                    cssFontSize: '15px',
                                                    paddingRight: '20',
                                                },
                                                {
                                                    xtype: 'button',
                                                    iconCls: 'fa HandPointRight',
                                                    text: '任务指派',
                                                    plain: true,
                                                    bind: {
                                                        disabled: '{button6_disabled}',
                                                    },
                                                    listeners: {
                                                        click: '{button6_click}',
                                                    },
                                                },
                                                {
                                                    xtype: 'button',
                                                    text: '任务解绑',
                                                    iconCls: 'element CloseBold',
                                                    plain: true,
                                                    bind: {
                                                        disabled: '{button7_disabled}',
                                                    },
                                                    listeners: {
                                                        click: '{button7_click}',
                                                    },
                                                },
                                            ],
                                            hidden: false,
                                            disabled: false,
                                            loading: false,
                                            cls: '',
                                            alignRight: false,
                                            isFlat: true,
                                            isBorder: [
                                                '0px',
                                                '0px',
                                                '0px',
                                                '0px',
                                            ],
                                        },
                                        {
                                            xtype: 'aggrid',
                                            columns: [
                                                {
                                                    dataIndex: 'task_id',
                                                    header: '任务ID',
                                                    xtype: 'aggridcolumn',
                                                    editable: false,
                                                    replaceFor: '',
                                                    dict: 'ASSIGN_STATE',
                                                    hidden: true,
                                                },
                                                {
                                                    dataIndex: 'obtain_staff_name',
                                                    header: '任务索取人',
                                                    xtype: 'aggridcolumn',
                                                    editable: false,
                                                    replaceFor: '',
                                                },
                                                {
                                                    dataIndex: 'task_status',
                                                    header: '任务状态',
                                                    xtype: 'aggridcolumn',
                                                    dict: 'OUTBOUND_STATUS',
                                                },
                                                {
                                                    dataIndex: 'task_code',
                                                    header: '任务号',
                                                    xtype: 'aggridcolumn',
                                                    hidden: true,
                                                },
                                                {
                                                    dataIndex: 'obtain_staff_id',
                                                    header: '拣货员',
                                                    xtype: 'aggridcolumn',
                                                    hidden: true,
                                                },
                                                {
                                                    dataIndex: 'location_code',
                                                    header: '集货位/作业工位',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'project_name',
                                                    header: '项目名称',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'rece_area',
                                                    header: '收货地区',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'rece_address',
                                                    header: '收货详细地址',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'logistics_order_code',
                                                    header: '物流订单号',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'customer_order_code',
                                                    header: '客户订单编号',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'customer_name',
                                                    header: '客户名称',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'owner_name',
                                                    header: '货主名称',
                                                    xtype: 'aggridcolumn',
                                                },
                                                {
                                                    dataIndex: 'so_code',
                                                    header: '出库通知单号',
                                                    xtype: 'aggridcolumn',
                                                    hidden: true,
                                                },
                                            ],
                                            hidden: false,
                                            disabled: false,
                                            loading: false,
                                            cls: '',
                                            height: '300px',
                                            pagination: true,
                                            pageSize: 50,
                                            autoLoad: false,
                                            rowNumber: false,
                                            hiLightSelectedRow: false,
                                            isBindMode: false,
                                            rowDragable: false,
                                            pageSizeOption: [
                                                {
                                                    value: '20',
                                                },
                                                {
                                                    value: '50',
                                                },
                                                {
                                                    value: '100',
                                                },
                                                {
                                                    value: '200',
                                                },
                                                {
                                                    value: '300',
                                                },
                                                {
                                                    value: '500',
                                                },
                                                {
                                                    value: '1000',
                                                },
                                            ],
                                            heightMode: 'fit',
                                            reference: 'grid2',
                                            mode: 'checkbox',
                                            title: '',
                                            dataSource: {
                                                sqlId: 'queryPickTaskItems',
                                                method: 'invoke',
                                                params: {
                                                    so_id: 'watch:{grid1.selection.so_id}',
                                                },
                                            },
                                            bind: {
                                                emptyText: '{grid2_emptyText}',
                                            },
                                        },
                                    ],
                                    xtype: 'splitarea',
                                },
                            ],
                            hidden: false,
                            disabled: false,
                            loading: false,
                            cls: '',
                            direction: 'vertical',
                            hiddenSplit: false,
                            title1: '',
                            title2: '',
                            collapse1: false,
                            collapse2: false,
                            isBorder: [
                                '0px',
                                '0px',
                                '0px',
                                '0px',
                            ],
                            heightMode: 'fit',
                        },
                    ],
                    extendProps: [],
                    isFlex: true,
                    listeners: {
                        onMounted: '{onMounted}',
                    },
                },
            }
            //@VExportData-End

        },
    methods: {
        onMounted() {
            this.form.operator = window.$user.nickname
        },
        button3_click() {
            this.refs.grid1.reload()
        },
        button1_click() {
            system.showLoading()
            system.invokeServer('/pages/outbound/manage_task/ManageTask@checkMergeTask',{so_ids:this.grid1.selections.map(it => it.so_id)})
                .then((res)=>{
                    if(res.success){
                        system.showDialog('/outbound/manage_task/DepartDialog.vue',{title:'任务指派',so_ids:this.grid1.selections.map(it => it.so_id),task_ids:[]})
                        .then(res =>{
                            this.refs.grid1.reload()
                        })
                    }
                }).finally(()=>{system.clearLoading()})
        },
        button2_click() {

            //进行解绑操作
            system.showLoading()
            system.invokeServer('/pages/outbound/manage_task/ManageTask@unBind',{
                so_ids:this.grid1.selections.map(it => it.so_id),task_ids:[]
            }).then((res)=>{
                if(res.success){
                    system.msg('解绑完成')
                    this.refs.grid1.reload()
                }
            }).finally(()=>{
                system.clearLoading()
            })
        },
        button4_click() {
            const selectedRows = this.refs.grid1.getSelectedRows()
            if(!selectedRows || selectedRows.length <= 0){
                system.showErrorDialog("请选择需要打印的订单")
                return
            }
            const parameters = selectedRows.map(row => {
                return {
                    so_id: row.so_id,
                    logistics_order_code: row.logistics_order_code,
                    so_code: row.so_code
                    }
            })
            console.log('parameters', parameters)
            ZPrintTools.showTemplateDialog("CODE_002", parameters).finally()
        },
        button5_click() {
            this.form=[]
        },
        grid1_onRowClick() {
            console.log(this.grid1.selection)
        },
        button6_click() {
            system.showDialog('/outbound/manage_task/DepartDialog.vue',{title:'任务指派',task_ids:this.grid2.selections.map(it => it.task_id),so_ids:[]})
                .then((res)=>{
                    this.refs.grid2.reload()
                })
        },
        button7_click() {
            system.showLoading()
            system.invokeServer('/pages/outbound/manage_task/ManageTask@unBind',{
                task_ids: this.grid2.selections.map(it => it.task_id),so_ids:[]
            }).then((res)=>{
                this.refs.grid2.reload()
            }).finally(()=>{system.clearLoading()})
        },
    },
    computed: {
        button1_disabled() {
            return !this.grid1.selection
        },
        button2_disabled() {
            return !this.grid1.selection
        },
        button6_disabled() {
            return !this.grid2.selection
        },
        button7_disabled() {
            return !this.grid2.selection
        },
        grid2_emptyText() {
            if(!this.grid1.selection?._rid){
                return '请选择订单'
            }

            return undefined
        },
    },
    watch: {},
}
